<!--
 * @Author: your name
 * @Date: 2021-12-14 21:46:37
 * @LastEditTime: 2021-12-25 22:48:53
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \homeStayMS\src\main\resources\static\vue\common-components\SearchBar\SearchBar.vue
-->

<!-- 

-->
<template>
  <section>
    <el-form ref="form" size="small" :model="searchSelect" :inline="true">
      <el-form-item
        v-for="item in searchFormList"
        :label="item.label"
        :prop="item.prop"
        :key="item.prop"
      >
        <!-- 普通的输入框 -->
        <el-input
          v-if="item.type === 'input'"
          v-model.trim="searchSelect[item.prop]"
          :placeholder="item.placeholder"
        ></el-input>

        <!-- 复合型输入框 -->
        <el-input
          v-if="item.type === 'composite'"
          :placeholder="item.placeholder || '请输入'"
          v-model="searchSelect[item.inputProp]"
        >
          <el-select
            v-model="searchSelect[item.selectProp]"
            slot="prepend"
            :style="
              !!item.selectWidth ? 'width:' + item.selectWidth : 'width:100px'
            "
          >
            <el-option
              v-for="elem in item.options"
              :label="elem.label"
              :value="elem.value"
              :key="elem.value"
            ></el-option>
          </el-select>
        </el-input>

        <!-- 按钮 -->
        <el-button
          v-if="item.type === 'button'"
          :type="item.btnType"
          :icon="item.icon"
          :size="item.size || 'small'"
          @click="!!item.handle ? item.handle() : ''"
        >
          {{ item.name }}
        </el-button>
      </el-form-item>
    </el-form>
  </section>
</template>

<script>
export default {
  name: 'SearchBar',

  /**  */
  props: {
    /** 搜索组件 双向绑定对象 即搜索组件选择的内容 表单对象 */
    searchSelect: { type: Object, default: () => {} },

    /** 搜索组件配置数组 */
    searchFormList: { type: Array, default: () => [] },
  },

  data() {
    return {};
  },

  methods: {
    resetForm() {
      this.$refs.form.resetFields();
    },
  },
};
</script>
